package com.travel.mapper.log;

import com.travel.model.entity.log.ApiLog;
import org.apache.ibatis.annotations.*;

import java.time.LocalDateTime;
import java.util.List;
import java.util.Map;
//api日志mapper 查询api日志 插入api日志 
@Mapper
public interface ApiLogMapper {
    
    @Select("SELECT path, COUNT(1) as count " +
            "FROM api_logs " +
            "GROUP BY path " +
            "HAVING COUNT(1) > 0 " +
            "ORDER BY count DESC")
    @Results({
        @Result(column = "path", property = "path"),
        @Result(column = "count", property = "count")
    })
    List<Map<String, Object>> getApiStatistics();
    
    @Select("SELECT * FROM api_logs " +
            "ORDER BY request_time DESC LIMIT 100")
    List<ApiLog> findByRequestTimeBetween(LocalDateTime start, LocalDateTime end);
    
    @Insert("INSERT INTO api_logs(path, method, request_time, response_time, status_code, client_ip, user_agent) " +
            "VALUES(#{path}, #{method}, #{requestTime}, #{responseTime}, #{statusCode}, #{clientIp}, #{userAgent})")
    @Options(useGeneratedKeys = true, keyProperty = "id")
    int insert(ApiLog apiLog);
} 